package request_manage_models

import (
	"errors"
	"storeManageApi/models/dbModels"
	"storeManageApi/utils"
)

type NewInNotes struct {
	ActionNumber   int    `json:"actionNumber"`
	ActionUserName string `json:"actionUserName"`
	Description    string `json:"description"`
	GoodsUid       string `json:"goodsUid"`
	ManageUserName string `json:"manageUserName"`
}

func (receiver NewInNotes) ConvertInNotes() dbModels.InNotes {
	return dbModels.InNotes{
		Base: dbModels.Base{
			Uid:         utils.RandomUid(),
			Description: receiver.Description,
		},
		ActionNumber:   receiver.ActionNumber,
		ActionUserName: receiver.ActionUserName,
		GoodsUid:       receiver.GoodsUid,
		ManageUserName: receiver.ManageUserName,
	}
}

func (receiver NewInNotes) Isvalidated() error {
	if receiver.GoodsUid == "" {
		return errors.New("操作物品不能为空")
	}
	if receiver.ActionNumber <= 0 {
		return errors.New("操作数量不合法")
	}
	if receiver.ActionUserName == "" {
		return errors.New("操作人员姓名不合法")
	}
	if receiver.ManageUserName == "" {
		return errors.New("负责人员姓名不合法")
	}
	return nil
}
